class FlaregunIgniteProj extends FlaregunProj;

var bool		bActive,bIgnite;
var	vector		OldLoc;
var	KFMonster	StuckTo;
var	float		FireStartTime,NextFireTime,NextCheckTime,SelfDestructTime;
var	int			Ignites;

function PostNetBeginPlay();

function Destroyed()
{
	if (FlareSmoke != none)
		FlareSmoke.Destroy();
	Super.Destroyed();
}


simulated function PostBeginPlay()
{
	SelfDestructTime = Level.TimeSeconds + 15.0;
	bActive = true;
	bIgnite = false;
	Super.PostBeginPlay();
}

simulated function ProcessTouch( actor Other, vector HitLocation )
{

	if ( !bActive || StuckTo != none )
		return;
		
	if ( KFMonster(Other) != none )
	{
		Stick(Other,HitLocation);
		return;
	}

	if (Other.IsA('NetKActor'))
		KAddImpulse(Velocity,HitLocation,);

	// Stop the grenade in its tracks if it hits an enemy.
	if ( !Other.bWorldGeometry && ((Other != Instigator && Other.Base != Instigator /*&& bHitIsCloseToCenter*/ )|| bCanHitOwner) )
		Velocity = Vect(0,0,0);
}

simulated function Stick(actor HitActor, vector HitLocation)
{
	local name NearestBone;
	local float dist;

	StuckTo=KFMonster(HitActor);
	
	SetPhysics(PHYS_None);

	NearestBone = GetClosestBone(HitLocation, HitLocation, dist , 'CHR_Spine2' , 15 );
	HitActor.AttachToBone(self,NearestBone);
	
	FireStartTime = Level.TimeSeconds + 2.0;
}

simulated function Tick(float DT)
{
	if ( bActive && SelfDestructTime < Level.TimeSeconds )
	{
		Explode(Self.Location,vect(0,0,0));
	}

	if ( !bIgnite && StuckTo != none && FireStartTime < Level.TimeSeconds )
	{
		bIgnite = true;
		StuckTo.ZombieCrispUp();
	}
	
//	if ( bActive && NextCheckTime < Level.TimeSeconds && StuckTo != none )
//	{
//		if ( OldLoc == Self.Location )
//		{
//			bActive = false;
//		}
//		OldLoc = Self.Location;
//		NextCheckTime = Level.TimeSeconds + 1.0;
//	}
	
	if ( bIgnite && NextFireTime < Level.TimeSeconds )
	{
		StuckTo.TakeDamage(Damage*0.5,Instigator,Self.Location,vect(0,0,0),MyDamageType);
		HurtRadius(Damage*0.5,DamageRadius,MyDamageType,0,StuckTo.Location);
		NextFireTime = Level.TimeSeconds + 0.5;
		--Ignites;
		if ( Ignites < 1 )
		{
			Explode(Self.Location,vect(0,0,0));
		}
	}

	Super.Tick(DT);
}

defaultproperties
{
	Speed=1600.000000
    MaxSpeed=1600.000000
    bCollideActors=True
	MyDamageType=class'DamTypeFlare'
	Ignites=10
	Damage=40
	DamageRadius=175.0
}
